<template>
	<view class="groupinfo" style="padding-bottom: 108rpx;" v-if="info">
		<view class="groupinfo_box">
			<view class="groupinfo_top">
				<view class="group_img_box">
					<image class="group_img" :src="picUrl+info.logo" mode="aspectFill"></image>
					<image v-if="info.club_border" class="group_border_img" :src="picUrl+info.club_border"
						mode="aspectFill"></image>
				</view>
				<view class="group_title_box">
					<view class="display_flex" style="justify-content: space-between;">
						<view class="f-16 f-w">{{info.title}}</view>
						<image @click="showGroupPopup" class="group_qrcode_mini" :src="onlinePic+'qrcode.png'">
						</image>
					</view>
					<view class="group_addr_box" v-if="info.address">
						<uni-icons type="location" size="9" color="#00A0DC"></uni-icons>
						<view>{{info.address}}</view>
					</view>
					<view class="group_user_box">成员{{info.join_count}}人 | 活动{{info.huodong_count}}场</view>
				</view>
			</view>
			<view class="groupinfo_desc">
				<text>{{info.desc}}</text>
			</view>
		</view>
		<view class="swiper_group_box" v-if="activebannerlist.length>0">
			<swiper class="swiper_group" circular :autoplay="false" :interval="3000" :duration="500"
				@change="changeSwiper">
				<swiper-item v-for="(item,index) in activebannerlist" :key="item.huodong_id"
					@click="goActiveInfo(item.huodong_id,item.huodong_status)">
					<image class="swiper_group_img" :src="picUrl+item.pic" mode="aspectFill"></image>
					<view class="swiper_group_mask_box">
						<view class="swiper_group_mask_title">{{item.title}}</view>
					</view>
					<image class="swiper_group_newactive_img" :src="onlinePic+'new_active_icon.png'"></image>
					<image v-if="item.huodong_status==0" class="group_cell_img_tips"
						:src="onlinePic+'active_face1.png'"></image>
					<image v-if="item.huodong_status==1" class="group_cell_img_tips" :src="onlinePic+'active_ing1.png'">
					</image>
					<image v-if="item.huodong_status==2" class="group_cell_img_tips" :src="onlinePic+'active_end1.png'">
					</image>
				</swiper-item>
			</swiper>
			<view class="swiper_dot_box">
				<view v-for="(item,index) in activebannerlist" :key="index"
					:class="current==index?'swiper_dot swiper_dot_active':'swiper_dot'"></view>
			</view>
		</view>
		<view class="index_active_box">
			<view class="index_active_cell" v-for="(item,index) in list" :key="item.huodong_id"
				@click="goActiveInfo(item.huodong_id,item.huodong_status,item.title)">
				<view v-if="item.huodong_status==0" class="index_active_img_box">
					<image v-if="item.cover" class="index_active_img" :src="picUrl+item.cover" mode="aspectFill">
					</image>
					<image v-else-if="item.pic" class="index_active_img" :src="picUrl+item.pic" mode="aspectFill">
					</image>
					<image v-else class="index_active_img" :src="picUrl+item.bbs_image[0]" mode="aspectFill">
					</image>
					<view v-if="item.huodong_status==0" class="index_active_progress_box">
						<view class="index_active_progress" :style="'width:'+item.proportion+'%;'">
							<view class="index_active_progress_mask"></view>
							<image class="index_active_progress_img" :src="onlinePic+'index_active_progress.png'"
								mode="aspectFill">
							</image>
							<view class="f-r c-white f-9 mr-10">{{item.proportion}}%</view>
						</view>
					</view>
				</view>
				<view v-if="item.huodong_status==1||item.huodong_status==2" class="index_active_imgs_box">

					<uni-row v-if="item.bbs_image.length==2||item.bbs_image.length==4" :gutter="10">
						<uni-col :span="12" v-for="itemi in item.bbs_image" :key="itemi">
							<image class="index_active_imgs" :src="picUrl+itemi" mode="aspectFill"></image>
						</uni-col>
					</uni-row>
					<uni-row v-else-if="item.bbs_image.length==3||item.bbs_image.length==6||item.bbs_image.length==9"
						:gutter="10">
						<uni-col :span="8" v-for="itemi in item.bbs_image" :key="itemi">
							<image class="index_active_imgs" :src="picUrl+itemi" mode="aspectFill"></image>
						</uni-col>
					</uni-row>
					<view v-else class="index_active_img_box">
						<image class="index_active_img" :src="item.cover?picUrl+item.cover:picUrl+item.pic"
							mode="aspectFill">
						</image>
					</view>

					<view v-if="item.bbs_num>0">
						<view v-if="item.huodong_status==1||item.huodong_status==2" class="index_active_sharenum">
							<image class="index_active_sharenum_img" :src="onlinePic+'index_active_sharenum.png'">
							</image>
							<view class="f-9 c-white ml-5">{{item.bbs_num}} 位车主分享</view>
						</view>
					</view>
				</view>
				<view class="display_flex mt-10">
					<view class="f-14 ellipsis flex-1">{{item.title}}</view>
					<text v-if="item.huodong_status==0" class="index_active_audit_before ml-5">招募中</text>
					<text v-if="item.huodong_status==1" class="index_active_audit_ing ml-5">进行中</text>
					<text v-if="item.huodong_status==2" class="index_active_audit_end ml-5">已结束</text>
				</view>
				<view class="display_flex mt-5">
					<view class="flex-1 display_flex">
						<view class="index_active_addr_box">
							<image class="index_active_addr_icon" :src="onlinePic+'index_active_addr_icon.png'">
							</image>
							<view class="c-999999 f-9" style="margin-left: 4rpx;">{{item.city}}</view>
						</view>
						<view class="f-10 c-999999 ml-5">{{item.start_time}} - {{item.end_time}}</view>
					</view>
				</view>
			</view>
			<view class="page_bottom_loading" :style="'padding-bottom:'+pdbottom+'rpx;'">{{loadingTitle}}</view>
		</view>
		<view class="mask_box" v-if="isShowGroupPopup" @click="colseGroupPopup"></view>
		<view class="group_qrcode_popup_box" v-if="isShowGroupPopup">
			<image class="group_qrcode_popup_bk" :src="picUrl+info.poster" :show-menu-by-longpress="true"
				mode="widthFix"></image>
		</view>
		<view v-if="userinfo.club_id!=club_id" class="group_tabs_box" @click="joinGroup()">
			<uni-icons type="plus-filled" size="20" color="#FFFFFF"></uni-icons>
			<span class="ml-10">申请加入车友会</span>
		</view>
	</view>
</template>

<script>
	import {
		getClubInfoBannerList,
		getClubInfo,
		getClubInfoActiveList,
		noticeTemplate,
		quitGroup,
		getGroupUserInfo,
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				club_id: '',
				info: '',
				params: {
					club_id: '',
					page: 1,
					size: 10
				},
				userinfo: {
					club_id: ''
				},
				activebannerlist: [],
				current: 1,
				list: [],
				loadingTitle: '',
				channel: '',
				picUrl: app.globalData.picUrl,
				onlinePic: app.globalData.onlinePic,
				isShowGroupPopup: false,
				pdbottom: uni.getSystemInfoSync().safeAreaInsets.bottom ? uni.getSystemInfoSync().safeAreaInsets.bottom +
					60 : 60,
				btnbottom: uni.getSystemInfoSync().safeAreaInsets.bottom > 0 ? uni.getSystemInfoSync().safeAreaInsets
					.bottom : 0
			};
		},
		onShow() {
			if (uni.getStorageSync('onload') || uni.getStorageSync('groupload')) {
				this.userinfo = uni.getStorageSync('userinfo')
				this.getClubInfoBannerList()
				this.getClubInfoActiveList()
				this.getClubInfo()
				this.getGroupUserInfo()
				uni.removeStorage({
					key: 'onload'
				})
				uni.removeStorage({
					key: 'groupload'
				})
			}
		},
		onLoad(options) {
			this.params.club_id = options.club_id
			this.club_id = options.club_id
			this.channel = options.channel ? options.channel : ''
			if (uni.getStorageSync('access_token')) {
				this.userinfo = uni.getStorageSync('userinfo')
				this.getClubInfoBannerList()
				this.getClubInfoActiveList()
				this.getClubInfo()
				this.getGroupUserInfo()
			} else {
				uni.navigateTo({
					url: '/pages/login/login'
				})
				this.loadingTitle = "- 暂无更多 -"
			}

		},
		methods: {
			getClubInfo() {
				getClubInfo({
					club_id: this.club_id
				}).then(res => {
					if (res.state == 1) {
						this.info = res.data.info
						var params = {
							event_code: '车友会详情',
							path: 'pages/group/group',
							event_id: this.club_id,
							title: res.data.info.title,
							source_page: '',
							value: this.channel ? this.channel : '',
						}
						app.BurialPoint(params)
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			getClubInfoBannerList() {
				getClubInfoBannerList({
					club_id: this.club_id
				}).then(res => {
					if (res.state == 1) {
						this.activebannerlist = res.data.list
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			getClubInfoActiveList() {
				getClubInfoActiveList(this.params).then(res => {
					if (res.state == 1) {
						this.list = [...this.list, ...res.data.data]
						this.last_page = res.data.last_page
						this.current_page = res.data.current_page
						if (this.list.length == 0) {
							this.loadingTitle = "- 暂无更多 -"
						}
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			changeSwiper(e) {
				this.current = e.detail.current
			},
			goActiveInfo(huodong_id, huodong_status) {
				if (uni.getStorageSync('access_token')) {
					if (huodong_status == 0) {
						uni.navigateTo({
							url: '/pages/group/groupactiveinfo?huodong_id=' + huodong_id + '&club_id=' + this
								.club_id + '&channel=' + this
								.channel
						})
					} else {
						uni.navigateTo({
							url: '/pages/group/groupactive?huodong_id=' + huodong_id + '&club_id=' + this.club_id +
								'&channel=' + this
								.channel
						})
					}
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}


			},
			joinGroup() {
				var that = this
				if (uni.getStorageSync('access_token')) {

					if (that.userinfo.club_id > 0) {
						var modaltext = that.userinfo.club_name ? that.userinfo.club_name : '车友会'
						uni.showModal({
							content: '您已加入“' + modaltext + '”，点击“确认"退出当前车友会',
							confirmColor: '#00A0DC',
							cancelText: '再考虑下',
							confirmText: '确认退出',
							success: function(res) {
								if (res.confirm) {
									quitGroup({
										club_id: that.userinfo.club_id,
									}).then(res => {
										if (res.state == 1) {
											uni.showToast({
												title: '已退出',
												mask: true,
												icon: 'success',
												duration: 1500
											})
											uni.setStorage({
												key: 'onload',
												data: 'true',
												success() {}
											})
											that.getClubInfoBannerList()
											that.getClubInfoActiveList()
											that.getClubInfo()
											that.getGroupUserInfo()
										} else {
											uni.showToast({
												title: res.error[0],
												mask: true,
												icon: 'none',
												duration: 1500
											})
										}
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
									that.isSubmit = true
								}
							}
						});
					} else {
						// #ifdef  MP-WEIXIN
						uni.requestSubscribeMessage({
							tmplIds: ['kwpV3YHFx0TJQXZGE1dmXyPuKB5KEhhxSols7MgJYKk'],
							success: function(res) {
								noticeTemplate({
									template_type: 4 //4:车友会；5:活动报名结果；6:活动创建结果
								}).then(res => {
									if (res.state == 1) {
										uni.navigateTo({
											url: '/pages/group/groupjoin?club_id=' +
												that.info
												.club_id
										})
									} else {

									}
								})
							},
							fail: function(e) {
								console.log(e)
							}
						})
						// #endif
						// #ifndef  MP-WEIXIN
						uni.navigateTo({
							url: '/pages/group/groupjoin?club_id=' + that.info.club_id
						})
						// #endif
					}
					var params = {
						event_code: '车友会详情',
						path: 'pages/group/group',
						event_id: that.info.club_id,
						title: that.info.title,
						source_page: '车友会详情-申请加入车友会',
						value: '',
					}
					app.BurialPoint(params)
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}

			},
			getGroupUserInfo() {
				getGroupUserInfo({
					user_id: uni.getStorageSync('userinfo') ? uni.getStorageSync('userinfo').user_id : ''
				}).then(res => {
					if (res.state == 1) {
						this.userinfo = res.data.list
						uni.setStorage({
							key: 'userinfo',
							data: res.data.list,
							success: function() {

							}
						});

					} else {
						uni.removeStorage({
							key: 'access_token'
						})
					}
				})
			},
			showGroupPopup() {
				if (uni.getStorageSync('access_token')) {
					this.isShowGroupPopup = true
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
				var params = {
					event_code: '车友会详情',
					path: 'pages/group/group',
					event_id: this.info.club_id,
					title: this.info.title,
					source_page: '车友会详情-查看车友会海报',
					value: '',
				}
				app.BurialPoint(params)
			},
			colseGroupPopup() {
				this.isShowGroupPopup = false
			},
		},
		onPullDownRefresh() {
			this.params.page = 1
			this.list = []
			this.getClubInfoActiveList()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.current_page < this.last_page) {
				this.showLoading = true
				this.params.page = this.params.page + 1
				this.getClubInfoActiveList()
			} else {
				this.showLoading = false
				if (this.list.length > 0) {
					this.loadingTitle = "- 已经到底了 -"
				} else {
					this.loadingTitle = "- 暂无更多 -"
				}

			}
		},
		onShareAppMessage(res) {
			app.getShareTask()
			return {
				title: this.info.title,
				imageUrl: this.info.pic ? this.picUrl + this.info.pic : ''
			}
		}
	}
</script>

<style lang="scss">
	.groupinfo {
		padding: 30rpx;

		.groupinfo_box {
			border-radius: 8rpx;
			padding: 50rpx 30rpx;
			background-color: #F7F7F7;

			.groupinfo_top {
				display: flex;
				align-items: center;

				.group_img_box {
					width: 145rpx;
					height: 145rpx;
					position: relative;

					.group_img {
						width: 145rpx;
						height: 145rpx;
						border-radius: 8rpx;
						vertical-align: middle;
					}

					.group_border_img {
						position: absolute;
						top: 0;
						right: 0;
						bottom: 0;
						left: 0;
						width: 145rpx;
						height: 145rpx;
						z-index: 1;
						vertical-align: middle;
					}
				}

				.group_title_box {
					flex: 1;
					height: 150rpx;
					margin-left: 15rpx;
					position: relative;

					.group_qrcode_mini {
						width: 40rpx;
						height: 40rpx;
					}

					.group_addr_box {
						position: relative;
						color: #00A0DC;
						font-size: 18rpx;
						display: inline-flex;
						padding: 3rpx 10rpx;
						margin-top: 10rpx;
						border-radius: 8rpx;
						border: 1rpx solid #00A0DC;
					}

					.group_user_box {
						font-size: 24rpx;
						position: absolute;
						bottom: 2rpx;
						left: 0;
						right: 0;
					}
				}
			}

			.groupinfo_desc {
				color: #999999;
				font-size: 24rpx;
				margin-top: 20rpx;
				line-height: 40rpx;
			}

		}

		.swiper_group_box {
			width: 100%;
			height: 436rpx;
			margin-top: 40rpx;
			position: relative;

			.swiper_group {
				width: 100%;
				height: 436rpx;
				border-radius: 8rpx;

				.swiper_group_img {
					width: 100%;
					height: 436rpx;
					border-radius: 8rpx;
				}
			}

			.swiper_group_newactive_img {
				position: absolute;
				top: 20rpx;
				left: 20rpx;
				z-index: 1;
				width: 117rpx;
				height: 25rpx;
				vertical-align: middle;
			}

			.swiper_group_mask_box {
				height: 60rpx;
				display: flex;
				align-items: center;
				position: absolute;
				bottom: 0;
				right: 0;
				left: 0;
				z-index: 1;
				padding: 0 20rpx;
				opacity: 0.85;
				background-color: #191919;
				border-bottom-left-radius: 8rpx;
				border-bottom-right-radius: 8rpx;

				.swiper_group_mask_title {
					flex: 1;
					color: #ffffff;
					font-size: 24rpx;
				}
			}

			.swiper_dot_box {
				display: flex;
				align-items: center;
				justify-content: center;
				position: absolute;
				right: 30rpx;
				bottom: 18rpx;
				z-index: 1;

				.swiper_dot {
					width: 17rpx;
					height: 4rpx;
					margin-left: 20rpx;
					background-color: #ffffff;
				}

				.swiper_dot_active {
					width: 30rpx;
					height: 4rpx;
					background-color: #00A0DC;
				}
			}
		}

		.group_cell_img_tips {
			position: absolute;
			top: 0;
			right: 0;
			z-index: 1;
			width: 99rpx;
			height: 35rpx;
			vertical-align: middle;
		}

		.groupinfo_cell_box {
			margin-top: 40rpx;

			.groupinfo_cell {
				margin-bottom: 25rpx;

				.group_cell_img_box {
					width: 100%;
					height: 218rpx;
					position: relative;
				}

				.group_cell_img {
					width: 100%;
					height: 218rpx;
					border-radius: 8rpx;
				}

				.groupinfo_text {
					display: flex;
					align-items: center;
					padding: 15rpx 0;

					.groupinfo_title {
						flex: 1;
						font-size: 26rpx;
						font-weight: bold;
						line-height: 40rpx;
						letter-spacing: 1rpx;
					}

					.pic_icon_img {
						width: 27rpx;
						height: 22rpx;
						vertical-align: middle;
					}

					.read_icon_img {
						width: 34rpx;
						height: 24rpx;
						vertical-align: middle;
					}
				}
			}
		}

		.index_active_box {
			margin-top: 40rpx;

			.index_active_cell {
				margin-bottom: 50rpx;

				.index_active_img_box {
					width: 100%;
					position: relative;
					// border-radius: 8rpx;

					.index_active_img {
						width: 100%;
						height: 220rpx;
						vertical-align: middle;
						border-top-left-radius: 8rpx;
						border-top-right-radius: 8rpx;
					}

					.index_active_progress_box {
						width: 100%;
						height: 25rpx;
						position: relative;
						border-bottom-left-radius: 8rpx;
						border-bottom-right-radius: 8rpx;
						background-color: #C7E2EC;

						.index_active_progress {
							height: 25rpx;
							position: absolute;
							bottom: 0;
							left: 0;
							z-index: 1;
							border-top-right-radius: 16rpx;
							border-bottom-right-radius: 16rpx;
							border-bottom-left-radius: 16rpx;
							background-color: #00A0DC;
						}

						.index_active_progress_img {
							width: 100%;
							height: 25rpx;
							position: absolute;
							bottom: 0;
							left: 0;
							right: 0;
							z-index: 2;
							border-top-right-radius: 16rpx;
							border-bottom-right-radius: 16rpx;
							border-bottom-left-radius: 8rpx;
							vertical-align: middle;
						}

						.index_active_progress_mask {
							width: 220rpx;
							height: 25rpx;
							position: absolute;
							bottom: 0;
							left: 0;
							z-index: 3;
							background: linear-gradient(to right, #B9ECFF, transparent);
							border-bottom-left-radius: 8rpx;
							border-bottom-right-radius: 8rpx;
						}

					}
				}

				.index_active_imgs_box {
					width: 100%;
					position: relative;
					border-radius: 8rpx;

					.uni-col {
						margin-bottom: 10rpx;
					}

					.index_active_imgs {
						width: 100%;
						height: 220rpx;
						border-radius: 8rpx;
						vertical-align: middle;
					}

					.index_active_sharenum {
						position: absolute;
						right: 15rpx;
						bottom: 25rpx;
						z-index: 1;
						display: flex;
						align-items: center;
						justify-content: center;
						background-color: rgba(0, 0, 0, 0.75);
						padding: 6rpx;
						border-radius: 4rpx;

						.index_active_sharenum_img {
							width: 19rpx;
							height: 21rpx;
							vertical-align: middle;
						}
					}
				}

				.index_active_audit_before {
					color: #ffffff;
					font-size: 18rpx;
					padding: 4rpx 10rpx;
					border-radius: 4rpx;
					background-color: #EA4A34;
					vertical-align: middle;
					white-space: nowrap;
				}

				.index_active_audit_ing {
					color: #ffffff;
					font-size: 18rpx;
					padding: 4rpx 10rpx;
					border-radius: 4rpx;
					background-color: #07C061;
					vertical-align: middle;
					white-space: nowrap;
				}

				.index_active_audit_end {
					color: #ffffff;
					font-size: 18rpx;
					padding: 4rpx 10rpx;
					border-radius: 4rpx;
					background-color: #717171;
					vertical-align: middle;
					white-space: nowrap;
				}

				.index_active_addr_box {
					display: flex;
					align-items: center;
					justify-content: center;
					padding: 6rpx 12rpx;
					border-radius: 8rpx;
					border: 1rpx solid #CBCBCB;

					.index_active_addr_icon {
						width: 15rpx;
						height: 16rpx;
						vertical-align: middle;
					}
				}

				.emote_icon {
					width: 18rpx;
					height: 18rpx;
					margin-left: 4rpx;
					vertical-align: middle;
				}
			}
		}

		.group_tabs_box {
			color: #ffffff;
			font-size: 36rpx;
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			z-index: 1;
			padding: 38rpx 0;
			display: flex;
			align-items: center;
			justify-content: center;
			border-top-left-radius: 20rpx;
			border-top-right-radius: 20rpx;
			background-color: #00A0DC;

		}

	}
</style>